package top100;

import java.util.Arrays;

/**
 * @author Godc
 * @description
 */
public class AnalysisHistogram {
    public static void main(String[] args) {
        AnalysisHistogramSolution s = new AnalysisHistogramSolution();
        s.analysisHistogram(new int[]{3,2,7},2);
    }
}
class AnalysisHistogramSolution {
    public int[] analysisHistogram(int[] heights, int cnt) {
        Arrays.sort(heights);
        int i = 0,j = cnt-1,min = 1000001;
        int mini = 0,minj = 0;
        while(j<heights.length){
            if((heights[j]-heights[i])<min){
                min = heights[j]-heights[i];
                mini = i;
                minj = j;
            }
            else if((heights[j]-heights[i]) == min){
                if(heights[mini]>heights[i]){
                    mini = i;
                    minj = j;
                }
            }
            i++;
            j++;
        }
        int[] res = new int[minj-mini+1];
        for(int k = mini;k<=minj;k++){
            res[k-mini] = heights[k];
        }
        return res;
    }
}